package demo2;

public class LeetCode202 {
    public boolean isHappy(int n) {
        int left = n, right = sum(n);
        while(left != right) {
            left = sum(left);
            right = sum(right);
            right = sum(right);
            if(right == 1) return true;
        }
        return left == 1;
    }
    public static int sum(int n) {
        int sum = 0;
        while(n > 0) {
            int tmp = n % 10;
            sum += tmp * tmp;
            n /= 10;
        }
        return sum;
    }
}
